package com.example.demo.controller;

import com.example.demo.model.Book;
import com.example.demo.model.User;
import com.example.demo.service.BookCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 功能描述：
 *
 * @Author: Zhanghf
 * @Date: 2021/5/29 10:48
 */
@Controller
public class RankingController {
    @Autowired(required = false)
    private BookCacheService bookCacheService;
    @GetMapping("ranking")
    public String ranking(HttpServletResponse response, HttpServletRequest request, Model model, HttpSession session)
    {
        User user = (User) session.getAttribute("user");
        model.addAttribute("user",user);
        //热门推荐
        //热门推荐（根据点击量来推荐）
        List<Book> topxuanhuan = bookCacheService.hitsRank("玄幻奇幻");
        List<Book> topdushi =  bookCacheService.hitsRank("都市言情");
        List<Book> topwuxia =  bookCacheService.hitsRank("仙侠武侠");
        List<Book> toptongren = bookCacheService.hitsRank("同人网游");
        List<Book> topchuanyue = bookCacheService. hitsRank("穿越历史");
        List<Book> topkehuan = bookCacheService.hitsRank("科幻灵异");
        List<Book> hitsOver = bookCacheService.hitsRankOver();
        model.addAttribute("topxuanhuan", topxuanhuan)
                .addAttribute("topdushi", topdushi)
                .addAttribute("topkehuan", topkehuan)
                .addAttribute("topwuxia", topwuxia)
                .addAttribute("toptongren", toptongren)
                .addAttribute("topchuanyue", topchuanyue)
        .addAttribute("hitsOver",hitsOver);
        return "rankinglist";
    }
    @GetMapping("collect")
    public String collect(HttpServletResponse response, HttpServletRequest request, Model model, HttpSession session)
    {
        User user = (User) session.getAttribute("user");
        model.addAttribute("user",user);
        //热门推荐
        List<Book> topxuanhuan = bookCacheService.collectionsRank("玄幻奇幻");
        List<Book> topdushi =  bookCacheService.collectionsRank("都市言情");
        List<Book> topwuxia =  bookCacheService.collectionsRank("仙侠武侠");
        List<Book> toptongren = bookCacheService.collectionsRank("同人网游");
        List<Book> topchuanyue = bookCacheService. collectionsRank("穿越历史");
        List<Book> topkehuan = bookCacheService.collectionsRank("科幻灵异");
        List<Book> rankOver = bookCacheService.collectionsRankOver();
        model.addAttribute("topxuanhuan", topxuanhuan)
                .addAttribute("topdushi", topdushi)
                .addAttribute("topkehuan", topkehuan)
                .addAttribute("topwuxia", topwuxia)
                .addAttribute("toptongren", toptongren)
                .addAttribute("topchuanyue", topchuanyue)
        .addAttribute("rankOver",rankOver);

        return "collect";
    }
}
